package com.xinchuang.controller.targetSystem.api;

import com.xinchuang.common.*;
import com.xinchuang.entity.targetSystem.external.Blow;
import com.xinchuang.entity.targetSystem.external.ExternalTarget;
import com.xinchuang.entity.targetSystem.external.Task;
import com.xinchuang.fiter.NoToken;
import com.xinchuang.service.targetSystem.external.ApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName ApiController
 * @Description: TODO(外部接口Controller)
 * @Author zhangxuan
 * @Date 2021-03-30 14:33
 * @Verion V1.0
 */
@Api(value = "外部Controller", tags = {"外部接口"})
@RestController
@RequestMapping(value = "/api")
public class ApiController {

    @Resource
    private ApiService apiService;

    /**
     * 注册用户
     */
    private final String REGISTER_USER = "/register";
    /**
     * 导入目标
     */
    private final String IMPORT_TARGET = "/importTarget";
    /**
     * 获取要素
     */
    private final String GET_ELEMENT = "/getElement";
    /**
     * 获取打击评估
     */
    private final String BLOW_LEVEL = "/getBlow";
    /**
     * 获取子目标列表
     */
    private final String GET_SUB = "/getSubList";

    @NoToken
    @ApiOperation(value = "导入目标")
    @PostMapping(IMPORT_TARGET)
    public Result<Map<String, Object>> importTarget(
            @Validated @RequestBody ExternalTarget externalTarget
            ){
        return apiService.addTarget(externalTarget);
    }

    @NoToken
    @ApiOperation(value = "获取要素")
    @PostMapping(GET_ELEMENT)
    public Result getElement(
            @Validated @RequestBody Task task
            ) {
        return apiService.addTargetElse(task.getTaskId(), task.getTargetId());
    }

    @NoToken
    @ApiOperation(value = "获取打击评估")
    @PostMapping(BLOW_LEVEL)
    public Result getBlow(
            @Validated @RequestBody  Blow blow
            ) {
        return apiService.addBlow(blow);
    }

    @NoToken
    @ApiOperation(value = "获取子目标列表")
    @GetMapping(GET_SUB)
    public Result getSubList(
            @RequestParam(value = "targetId") String targetId
    ) {
        return apiService.getSubList(targetId);
    }

}